import SessionUtil, { JxbHttpClient } from '../../../data/session/session'
const Common = require('../../../utils/common.js');
Page({
    data: {
    },
    onLoad: function (options) {
        SessionUtil.getInstance().then(session=>{
            wx.setNavigationBarTitle({
                title: '登录'
            })
        })       
    },
    forgetPassword: function () {
        wx.navigateTo({
            url: '/pages/login/forget_password/forget_password'
        })
    },
    onLogin_SMC: function () {
        var page = this;
        var userName = page.data.phones;
        var passWord = page.data.password;
        var phonetest = /^0?1\d{10}$/;
        if (!userName) {
            Common.Alert('提示', '请输入手机号码');
            return false;
        } else if (!phonetest.test(userName)) {
            Common.Alert('提示', '请输入正确的手机号码');
            return false;
        }
        if (!passWord) {
            Common.Alert('登录提示', '请输入登录密码');
            return false;
        }
        wx.showLoading({
            title: '正在登录...',
        });
        (new JxbHttpClient()).post({
            url: 'AppMaster/Login/login',
            data: {
                userName: userName,
                password: passWord
            }
        }).then(jxbResp=>{
            wx.hideLoading();
            wx.setStorageSync('user_id', jxbResp.data.userId);
            wx.setStorageSync('phone', userName);
            wx.navigateBack({
                delta: 2
            })
        }).catch(err => {
            wx.hideLoading();
            Common.Alert('登录提示', err.message);
        });
    },
    updatepassword: function (e) {
        this.setData({
            password: e.detail.value
        })
    },
    updatephones: function (e) {
        this.setData({
            phones: e.detail.value
        })
    },
    onPullDownRefresh: function () {
        wx.stopPullDownRefresh();
    },
})